<%--
  Created by IntelliJ IDEA.
  User: 步步为莹
  Date: 2019/9/18
  Time: 23:31
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String id=request.getParameter("id");
    request.setAttribute("id",id);
%>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="author" content="order by dede58.com"/><title>后台管理系统</title>
    <link rel="stylesheet" href="../../../static/css/style.css">
    <link rel="stylesheet" href="../../../static/css/jquery.wysiwyg.old-school.css">
    
    <!-- jQuery AND jQueryUI -->
    <script type="text/javascript" src="../../../static/js/jquery.min.js"></script>
    <script type="text/javascript" src="../../../static/js/jquery-ui.min.js"></script>
    <script type="text/javascript" src="../../../static/js/min.js"></script>
    <!--<script type="text/javascript" src="js/index.js"></script>-->
</head>
<body class="modal white">
<script type="text/javascript" src="../../../static/js/main.js"></script>
<link rel="stylesheet" href="../../../static/css/style2.css">
<div id="content" class="white" style="margin-left:242px">
    <div class="bloc">
        <div class="title" style="margin-top:40px">更改部门</div>
        <div class="content">
            <form id="modify">
                <div class="input">
                    <input type="hidden" id="id" name="id">
                    <label>公司名称:</label>
                    <select name="countryId">
                        <option value="0">请选择</option>
                        <option value="1001">工程部</option>
                    </select></div>
                <div class="input">
                    <label for="name">部门名称:</label>
                    <input type="text" id="name" name="name">
                </div>
                <div class="input">
                    <label for="manager">部门经理:</label>
                    <input type="text" id="manager" name="manager">
                </div>
                <div class="input">
                    <label for="remark">备注:</label>
                    <input type="tex" id="remark" name="remark">
                </div>
                <div class="input">
                    <label for="remark">备注:</label>
                    <input type="date" id="create_time" name="create_time">
                </div>
                <input class="btn btn-danger" type="reset" id="reset" value="重置">
                <span onclick="commit()">提交</span>
            </form>
           
        </div>
    </div>
</div>
<div id="ui-datepicker-div" class="ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all"></div>
<script type="text/javascript">
    $.ajax({
        url:"<%=request.getContextPath()%>/departmentServlet",
        data:"Id=${id}&opr=selectdepartment",
        dataType:"json",
        type:"GET",
        success:function (result) {
            console.log(result);
            var $option=$("#countryId option");
            for (var i=0;i<$option.length;i++){
                if ($option.val()===result.dept_id){
                    $option.attr("selected","selected");
                }
            }
            $("#id").val(${id});
            $("#name").val(result.name);
            $("#manager").val(result.managerId);
            $("#remark").val(result.remark);
            $("#create_time").val(result.create_time);


        }
    })
    
    
    function commit() {
        var queryStr=$("form#modify").serialize();
        $.ajax({
            url:"<%=request.getContextPath()%>/departmentServlet",
            data:"opr=updatedepartment&"+queryStr,
            dataType:"text",
            type:"GET",
            success:function (result) {
                console.log(result);
                if (result==="true"){
                    alert("修改部门成功！");
                    window.location.href="department.jsp";
                }else {
                    alert("修改部门失败！");
                }
            }
        })
    }
</script>
</body>
</html>
